// pages/department-select/department-select.js
Page({
	data: {
		selectedCampus: '湘南院区',
		selectedDepartment: '内科',
		isLoading: false,
		subDepartments: [
			'呼吸内科',
			'消化内科',
			'心血管内科',
			'血液内科',
			'肾内科'
		]
	},

	onLoad() {
		console.log('医院科室选择页面加载')
	},

	selectDepartment(e) {
		const department = e.currentTarget.dataset.department
		const campus = this.data.selectedCampus
		console.log('选择了科室:', department, '当前院区:', campus)
		
		// 根据选择的科室和当前院区更新子科室列表
		let subDepartments = []
		
		switch(department) {
			case '内科':
				subDepartments = [
					'呼吸内科',
					'消化内科',
					'心血管内科',
					'血液内科',
					'肾内科'
				]
				break
			case '外科':
				subDepartments = [
					'肝胆脾外科',
					'心胸外科',
					'泌尿外科',
					'神经外科',
					'烧伤外科'
				]
				break
			case '儿科':
				subDepartments = [
					'呼吸科',
					'消化科',
					'神经科',
					'血液科',
					'心血管科'
				]
				break
			case '神经内科':
				subDepartments = [
					'脑血管病专科',
					'癫痫与睡眠障碍专科',
					'神经肌肉病专科',
					'头痛与神经痛专科',
					'认知障碍与痴呆专科'
				]
				break
			case '耳鼻喉科':
				subDepartments = [
					'耳显微外科',
					'耳神经外科',
					'喉显微外科',
					'鼻内镜外科',
					'鼻神经外科'
				]
				break
			case '眼科门诊':
				subDepartments = [
					'普通眼科门诊',
					'白内障专科门诊',
					'青光眼专科门诊',
					'眼外伤专科门诊',
					'眼底病专科门诊'
				]
				break
			case '皮肤科':
				subDepartments = [
					'普通皮肤科',
					'皮肤外科',
					'小儿皮肤科',
					'皮肤美容专科',
					'色素性皮肤病专科'
				]
				break
			case '心理科':
				subDepartments = [
					'普通心理科',
					'精神科',
					'心理咨询与治疗科',
					'儿童青少年心理科',
					'睡眠障碍专科'
				]
				break
			case '营养科':
				subDepartments = [
					'普通营养咨询科',
					'临床营养科',
					'妇幼营养科',
					'运动营养科',
					'老年营养科'
				]
				break
			case '全科门诊':
				subDepartments = [
					'家庭医生签约组',
					'多病共管与预防组',
					'跨学科协同组'
				]
				break
			case '麻醉科':
				subDepartments = [
					'心胸麻醉组',
					'小儿与产科麻醉组',
					'麻醉重症与疼痛组'
				]
				break
			case '康复中心':
				subDepartments = [
					'神经康复组',
					'骨科与运动康复组',
					'老年与慢性病康复组'
				]
				break
			case '疼痛科':
				subDepartments = [
					'神经病理性疼痛',
					'脊柱与关节疼痛',
					'癌性与复杂疼痛'
				]
				break
			default:
				subDepartments = [
					'门诊',
					'门诊',
					'门诊',
					'门诊',
					'门诊'
				]
		}
		
		this.setData({
			selectedDepartment: department,
			subDepartments: subDepartments
		})
	},

	selectCampus(e) {
		const campus = e.currentTarget.dataset.campus
		console.log('选择了院区:', campus)
		
		// 如果选择的是当前院区，不做任何操作
		if (campus === this.data.selectedCampus) {
			return
		}
		
		// 显示加载状态
		this.setData({
			isLoading: true
		})
		
		// 模拟网络请求延迟
		setTimeout(() => {
			// 根据院区设置不同的科室数据
			let defaultDepartment = '内科'
			let defaultSubDepartments = [
				'呼吸内科',
				'消化内科',
				'心血管内科',
				'血液内科',
				'肾内科'
			]
			
			this.setData({
				selectedCampus: campus,
				selectedDepartment: defaultDepartment,
				subDepartments: defaultSubDepartments,
				isLoading: false
			})
		}, 1500) // 1.5秒的加载时间
	},

	selectSubDepartment(e) {
		const subDepartment = e.currentTarget.dataset.subDepartment
		console.log('选择了子科室:', subDepartment)
		
		// 跳转到医生预约页面，传递科室信息和院区信息
		wx.navigateTo({
			url: `/pages/doctor-appointment/doctor-appointment?department=${this.data.selectedDepartment}&subDepartment=${subDepartment}&campus=${this.data.selectedCampus}`
		})
	}
}) 